package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsBusinessGroupMessageDao;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsMusicDao;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessGroupMessage;
import com.syni.mdd.yhd.common.all.entity.BmsMusic;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsMusicService extends BaseService<BmsMusic, Integer> {

    @Autowired
    BmsMusicDao bmsMusicDao;

    @Override
    public BmsMusicDao getBaseDao() {
        return bmsMusicDao;
    }

    public Map<String, Object> findBackMusic(Integer userId,Integer pageNum,Integer pageSize) {
        Pageable pageable = BmsCommonService.getPageable(pageNum,pageSize, Sort.Direction.DESC,"useTotal","createTime");
        List<BmsMusic> bmsMusicList = bmsMusicDao.findByIsDelete(Constants.COMMON_FLAG_FALSE_INT,pageable);
        //设置播放时间
        if(bmsMusicList != null && bmsMusicList.size() > 0){
            for(BmsMusic bmsMusic : bmsMusicList){
                bmsMusic.setDuration(bmsMusic.getDuration() * 1000);
            }
        }
        return ResultMapHelper.success(bmsMusicList, ResultMsg.MSG_GET_SUCCESS);
    }
}
